<template>
  <div class="user">
    <div class="user-table">
      <div class="user-table-tools">
        <el-button type="primary" @click="openCreateUser">新增</el-button>
      </div>
      <div class="user-table-list">
        <el-table :data="list" height="400">
          <el-table-column
            v-for="item in tableColumns"
            :key="item.prop"
            :prop="item.prop"
            :label="item.label"
          >
          </el-table-column>
        </el-table>
      </div>
    </div>
  </div>
  <create-user ref="createUserCom" />
</template>

<script setup>
import api from '@/http/index.js'
import { ref, reactive } from 'vue'
import CreateUser from './create/index.vue'
const createUserCom = ref()
const openCreateUser = () => {
  createUserCom.value.open()
}

let list = ref([])
const tableColumns = reactive([
  { prop: 'userId', label: '用户ID' },
  { prop: 'nickName', label: '用户名称' },
  { prop: 'userName', label: '账号' },
  { prop: 'password', label: '密码' },
  { prop: 'phonenumber', label: '电话' },
  { prop: 'email', label: '邮箱' },
  { prop: 'loginDate', label: '最后登录时间' },
  { prop: 'createDate', label: '创建时间' },
])
const getUsers = async () => {
  const res = await api.user.get()
  list.value = res.data.map((item) => ({
    ...item,
    ...(item?.user || {}),
  }))
}

getUsers()
</script>

<style lang="scss">
.user {
  width: 100%;
  height: 100%;
  background-color: #fff;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 14px;
  &-table {
    &-tools {
      margin-bottom: 16px;
    }
  }
}
</style>
